package com.summer.mall.expection.handler;

import com.summer.mall.common.ResponseService;
import com.summer.mall.expection.MallException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class MallExceptionHandler {

    @ExceptionHandler(MallException.class)
    @ResponseBody
    public ResponseService handlerMallExceptionHandler(MallException e) {
        return ResponseService.createByCodeErrorMessage(e.getCode(), e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ResponseService handlerExceptionHandler(Exception e) {
        return ResponseService.createBySuccessMessage(e.getMessage());
    }
}
